package cn.sumpu.app.guoguojie.biz.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


import org.springframework.transaction.annotation.Transactional;

import cn.sumpu.app.guoguojie.biz.MemberDetailBiz;
import cn.sumpu.app.guoguojie.dao.MemberDetailDao;
import cn.sumpu.app.guoguojie.domain.MemberDetail;
import cn.sumpu.app.guoguojie.exception.AppBusinessException;
import cn.sumpu.app.guoguojie.util.Common;

public class MemberDetailBizImpl implements MemberDetailBiz {

	
	private MemberDetailDao memberDetailDao;

	public void setMemberDetailDao(MemberDetailDao memberDetailDao) {
		this.memberDetailDao = memberDetailDao;
	}

	// 查询个性化资料页面
	@Override
	public MemberDetail getMemberDetailById(String member)
			throws AppBusinessException {
		if (Common.empty(member))
			return null;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("member", member);
		List<MemberDetail> detailList = memberDetailDao
				.getMemberDetailList(map);
		if (detailList != null && detailList.size() > 0) {
			MemberDetail d = detailList.get(0);
			/*Map<String, Object> mapPer = new HashMap<String, Object>();
			mapPer.put("member", d.getMember());
			d.setPersonalityList(memberDetailDao
					.getMemberPersonalityList(mapPer));*/
			return d;
		}
		return null;
	}

	// 查询会员的所有信息
	@Override
	public MemberDetail getMemberDetailAll(String member)
			throws AppBusinessException {
		if (Common.empty(member))
			return null;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("member", member);
		MemberDetail detail = memberDetailDao.getMemberDetailByMember(map);
		if (detail != null) {
			detail.setPersonalityList(memberDetailDao
					.getMemberPersonalityList(map));
			detail.setWorkList(memberDetailDao.getMemberWorkList(map));
			detail.setLearningList(memberDetailDao.getMemberLearningList(map));
			detail.setContactList(memberDetailDao.getMemberContactList(map));
			return detail;
		}
		return null;
	}

	@Override
	@Transactional(rollbackForClassName = { "cn.sumpu.app.guoguojie.exception.AppBusinessException" }, timeout = 10)
	public void saveMemberDetail(MemberDetail detail)
			throws AppBusinessException {
		if (detail == null)
			return;
		MemberDetail d=getMemberDetailById(detail.getMember()); 
		if (d == null) {
			memberDetailDao.insertMemberDetail(detail);
		} else {
			memberDetailDao.updateMemberDetail(detail);
		}
	}

	@Override
	public void updateMemberDetail(MemberDetail detail)
			throws AppBusinessException {
		memberDetailDao.updateMemberDetail(detail);
	}

}
